# 乌龟吃鱼游戏（oop）
# 1)假设游戏场景为范围（x, y）为0<=x<=10，0<=y<=10
# 2)游戏自动生成1只乌龟对象和10条鱼对象（位置随机）
# 3)它们的移动方向（上下左右）均随机
# 4)乌龟的最大移动能力是2（它随机选择移动1或2），鱼儿的最大移动能力是1
# 5)当移动到场景边缘，自动向反方向移动
# 6)乌龟初始化体力为100，每移动一次，体力消耗1
# 7)鱼的初始体力为10，每移动一次体力消耗1，消耗到零时需要停5秒不移动，后体力恢复为10（此条有余力可加）
# 8)当乌龟和鱼坐标重叠，乌龟吃掉鱼，乌龟体力增加20
# 9)乌龟每行动一次输出当前坐标[x,y]，吃掉鱼时输出提示
# 游戏结束条件：当乌龟体力值为0（乌龟死掉）或者鱼儿的数量为0（乌龟赢）游戏结束
#
# 提示：
# 把龟和鱼封装成类，定义龟类的属性：体力、坐标，方法：吃鱼和移动。鱼类的属性：名字、坐标，方法：移动
import random


class Tortoise:
    torturtle_p = 0
    list_torturtle = []

    def run_turtle(self, list_torturtle):
        self.list_torturtle = list_torturtle
        # print(list_torturtle)
        # print('_' * 12)
        tortoise_run = random.randint(1, 2)
        move_temp = random.randint(0, 3)  # 0 上 1 下 2 左 3右
        # print(move_temp)
        if move_temp == 0:
            list_torturtle[0] = [list_torturtle[0][0], list_torturtle[0][1] + tortoise_run]
        elif move_temp == 1:
            list_torturtle[0] = [list_torturtle[0][0], list_torturtle[0][1] - tortoise_run]
        elif move_temp == 2:
            list_torturtle[0] = [list_torturtle[0][0] - tortoise_run, list_torturtle[0][1]]
        elif move_temp == 3:
            list_torturtle[0] = [list_torturtle[0][0] + tortoise_run, list_torturtle[0][1]]

        if list_torturtle[0][0] < 0:
            list_torturtle[0] = [list_torturtle[0][0] * -1, list_torturtle[0][1]]
        elif list_torturtle[0][1] < 0:
            list_torturtle[0] = [list_torturtle[0][0], list_torturtle[0][1] * -1]

        return list_torturtle

    def power_torturtle(self, torturtle_p):
        self.torturtle_p = torturtle_p
        self.torturtle_p -= 1

        return self.torturtle_p


class Fish:
    list_fish = []
    fish_p = 0

    def run_fish(self, list_fish):
        self.list_fish = list_fish
        # print(list_fish)
        # print('_' * 12)
        move_temp = random.randint(0, 3)  # 0 上 1 下 2 左 3右
        list_fish_len = len(list_fish)
        # print(move_temp)
        if move_temp == 0:
            for i in range(0, list_fish_len):
                list_fish[i] = [list_fish[i][0], list_fish[i][1] + 1]
        elif move_temp == 1:
            for i in range(0, list_fish_len):
                list_fish[i] = [list_fish[i][0], list_fish[i][1] - 1]
        elif move_temp == 2:
            for i in range(0, list_fish_len):
                list_fish[i] = [list_fish[i][0] - 1, list_fish[i][1]]
        elif move_temp == 3:
            for i in range(0, list_fish_len):
                list_fish[i] = [list_fish[i][0] + 1, list_fish[i][1]]
        for i in range(0, list_fish_len):
            if list_fish[i][0] < 0:
                list_fish[i] = [list_fish[i][0] * -1, list_fish[i][1]]
            elif list_fish[i][1] < 0:
                list_fish[i] = [list_fish[i][0], list_fish[i][1] * -1]
        return list_fish

    def power_fish(self, fish_p):
        self.fish_p = fish_p
        self.fish_p -= 1

        return self.fish_p


del_fish = []
temp = 0
fish = 10
tortoise = 100
fish_list = ['', '', '', '', '', '', '', '', '', '']
tortoise_list = ['']
tortoise_list[0] = [random.randint(1, 10), random.randint(1, 10)]
print('乌龟在{}'.format(tortoise_list[0]))
for i in range(0, 10):
    fish_list[i] = [random.randint(1, 10), random.randint(1, 10)]
    print('第{0}鱼在{1}'.format(i + 1, fish_list[i]))

print('-' * 20)
# 开始操作
# while tortoise < 0:

F = Fish()
T = Tortoise()
while True:
    new_power_fish = F.power_fish(fish)
    tortoise = T.power_torturtle(tortoise)
    if tortoise == 0:
        break
    else:
        temp += 1
        new_run_fish = F.run_fish(fish_list)  # 鱼移动方向
        new_run_tortoise = T.run_turtle(tortoise_list)  # 龟移动方向
        print('移动{0}次后乌龟在{1},体力为{2}'.format(temp, new_run_tortoise[0], tortoise))
        for i in range(0, len(new_run_fish)):
            print('移动{0}次后第{1}鱼在{2},体力为{3}'.format(temp, i + 1, new_run_fish[i], new_power_fish))
            pass

        if new_run_tortoise[0] in new_run_fish:
            tortoise += 20
            print('-' * 20)
            index_fish = new_run_fish.index(new_run_tortoise[0])
            if index_fish in del_fish:
                del_fish.append(index_fish + 1 + 1)
            else:
                del_fish.append(index_fish + 1)
            print('乌龟移动{0}次后在{1}位置吃到鱼{2}了！！！'.format(temp, new_run_tortoise[0], index_fish + 1))
            del new_run_fish[index_fish]
            # new_run_fish[index_fish] = [['', '']]
        elif len(new_run_fish) == 10 and temp > 1:
            print('一条没吃到')
        print('-' * 20)

for i in del_fish:
    print('鱼{}被吃了'.format(i), end='  ')
